window.workspace = function(){
	var response  = <?#$respons?>;
	var store, grid, sm, win, form, imwin, imform;
	var sid = {'userid':Ext.id(), 'tagid':Ext.id(), 'query':Ext.id(), 'status':Ext.id()};
	function addForm(rows){
		if(!win) {
		    form = new Ext.form.FormPanel({
				frame		: true,
				border		: false,
				bodyStyle	: 'padding:8px;',
		        labelWidth	: 140,
		        labelAlign  : 'right',
		        fileUpload  : true,
		    	defaults	: {
		    		xtype	  : 'textfield'
		    	},
		    	items		: [{
					xtype		: 'hidden',
					name		: 'id',
					value		: 0
				},{
					xtype		: 'textfield',
					fieldLabel	: '直播间编号[StudioNo]',
					width		: 160,
					name		: 'studiono',
					maxLength   : 15,
					allowBlank	: false
				},{
					xtype		: 'textfield',
					fieldLabel	: '直播间标题[Title]',
					width		: 320,
					name		: 'title',
					maxLength   : 64,
					allowBlank	: false
				},{
					xtype		: 'textfield',
					inputType 	: 'file', 
			 		fieldLabel	: '封面图[Cover]',
					name		: 'Filedata'
				},{
					xtype		: 'combo',
					store		: new Ext.data.JsonStore({
						url	: '/admin/live/share/dotags.html',
						autoDestroy: true,
						fields: ['id', 'name'],
						root: 'dataset'
					}),
					name			: 'tagids',
					hiddenName		: 'tagids',
					displayField	: 'name',
					valueField		: 'id',
					emptyText		: 'selected...',
					minChars		: 1,
					 pageSize		: 10,
		            listWidth		: 258,
		            width			: 120,
					typeAhead		: true,
					typeAheadDelay  : 0,
					triggerAction	: 'all',
					enableKeyEvents : true,
					fieldLabel		: '分类[Tag]',
					mode			: 'remote'
				},{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.yes2no)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '是否略质流[IsCasual]',
		            width			: 120,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'iscasual',
		            name			: 'iscasual'
		        },{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.yes2no)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '是否测试[IsTester]',
		            width			: 120,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'testing',
		            name			: 'testing'
		        },{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.yes2no)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '是否可疑[IsSuspicion]',
		            width			: 120,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'isdoubt',
		            name			: 'isdoubt'
		        },{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.yes2no)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '是否星标推荐[IsCurated]',
		            width			: 120,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'iscurated',
		            name			: 'iscurated'
		        },{
		    		xtype		: 'lovcombo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.area)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '默认Forward配置',
		            width			: 320,
					triggerAction	: 'all',
					hiddenName		: 'def_forward',
		            name			: 'def_forward'
		        },{
					xtype		: 'textfield',
					fieldLabel	: '流最近Forward配置',
					width		: 320,
					name		: 'nowforwardname',
					disabled   	: true
				},{
					xtype		: 'textfield',
					fieldLabel	: '最近推流地址[RtmpAddr]',
					width		: 320,
					name		: 'rtmp',
					disabled   	: true
				}]
			});
			win = new Ext.Window({
				title	: '新增[Add]',
				iconCls	: 'icon-add',	
				width	: 520,
				items	: [form],
				closeAction : 'hide',
				bbar 	: {
					xtype		: 'toolbar',
					buttonAlign	: 'right',
					items		: [{
						text	: '保存[Save]', 
						iconCls	: 'icon-save',
						url     : '/admin/live/basic/studio/dosave.html',
						handler	: function(){
						if(!form.getForm().isValid())
		        			return;
		        		form.getForm().submit({
		        			waitMsg		: GLang['30017'],
							waitTitle 	: GLang['30003'],
			        		clientValidation: true,
			        		url		: '/admin/live/basic/studio/dosave.html',
				        	success	: function(form, action) {
				        		store.reload();
				        		win.hide();
							},
							failure	: main.submitFailure
				    	});
					}}]
				}
			});
		}
		var id = Ext.isObject(rows)? rows.id:0;
		win.setTitle((id > 0)? '编辑[Edit]':'新增[Add]');
		win.setIconClass((id > 0)? 'icon-edit':'icon-add');
		win.show();
		if(id < 1) {
			form.getForm().reset();
		} else {
			form.getForm().loadRecord(rows);
			form.getForm().findField('tagids').setRawValue(rows.get('tags'));
			form.getForm().findField('def_forward').setValue(rows.get('defforwardids'));
			form.getForm().findField('def_forward').setRawValue(rows.get('defforwardname'));
		}
	};
	//设置IM的时间限制
	function doImTime(){
		if(!imwin) {
		    imform = new Ext.form.FormPanel({
				frame		: true,
				border		: false,
				bodyStyle	: 'padding:8px;',
		        labelWidth	: 120,
		        labelAlign  : 'right',
		    	items		: [{
					xtype		: 'numberfield',
					fieldLabel	: '禁言时间[GagTime]',
					width		: 120,
					name		: 'gagexpire',
					allowBlank	: false
				},{
					xtype		: 'numberfield',
					fieldLabel	: '踢人时间[KickTime]',
					width		: 120,
					name		: 'kickexpire',
					allowBlank	: false
				}]
			});
			imwin = new Ext.Window({
				title	: '设置[IM]时间[LimitTime]',
				iconCls	: 'icon-edit',	
				width	: 320,
				items	: [imform],
				closeAction : 'hide',
				bbar 	: {
					xtype		: 'toolbar',
					buttonAlign	: 'right',
					items		: [{
						text	: '保存[Save]', 
						iconCls	: 'icon-save',
						url   	: '/admin/live/im/dolimitset.html',
						handler	: function(){
						if(!imform.getForm().isValid())
		        			return;
						imform.getForm().submit({
							waitMsg		: GLang['30017'],
							waitTitle 	: GLang['30003'],
			        		clientValidation: true,
			        		url		: '/admin/live/im/dolimitset.html',
				        	success	: function(form, action) {
				        		imwin.hide();
							},
							failure	: main.submitFailure
				    	});
					}}]
				}
			});
		}
		imform.getForm().load({url:'/admin/live/im/dolimitget.html', success:function(form, res){
			imform.getForm().findField("kickexpire").setValue(res.result.kickexpire);
			imform.getForm().findField("gagexpire").setValue(res.result.gagexpire);
		}, failure : function(form, res){
			imform.getForm().findField("kickexpire").setValue(res.result.kickexpire);
			imform.getForm().findField("gagexpire").setValue(res.result.gagexpire);
		}});
		imwin.show();
	};
	//设置推荐、星标推荐
	function doSets(field) {
		var rcs = grid.sm.getSelections();
		if(Ext.isEmpty(rcs)) {
			Ext.Msg.alert(GLang['30003'], GLang['30020']);
			return;
		}
		var ids= [];
		Ext.each(rcs, function(item){
			ids.push(item.get('id'));
		});
		Ext.Msg.confirm(GLang['30003'], GLang['30023'], function(btn){
			if(btn=="yes") {
				Ext.Ajax.request({
					url		: '/admin/live/basic/studio/dosets.html',
					params	: {'ids':ids.join(','), 'field':field},
					success : function(resp, req){
						var data = Ext.decode(resp.responseText);
						if(data.code == 0) {
							store.reload(); 
						} else {
							Ext.Msg.alert(GLang['30003'], data.msg);
						}
					}
				});
			}
		});
	};
	function doStatus() {
		var rcs = grid.sm.getSelections();
		if(Ext.isEmpty(rcs)) {
			Ext.Msg.alert(GLang['30003'], GLang['30020']);
			return;
		}
		var ids= [];
		Ext.each(rcs, function(item){
			ids.push(item.get('id'));
		});
		Ext.Msg.prompt(GLang['30029'], GLang['30028'], function(btn, memo){
			if(btn=="ok") {
				var remark = String(memo).trim();
				if (!remark) {
					Ext.Msg.alert(GLang['30003'], GLang['30028']);
					return;
				}
		    	Ext.Ajax.request({
					url		: '/admin/live/basic/studio/dostatus.html',
					params	: {'ids':ids.join(','), 'status':1, 'remark':remark},
					success : function(resp, req) {
						var data = Ext.decode(resp.responseText);
						if(data.code == 0) {
							store.reload(); 
						} else {
							Ext.Msg.alert(GLang['30003'], data.msg);
						}
					}
				});
			}
			
		}, null, true);
    };
    sm    = new Ext.grid.CheckboxSelectionModel();
	store = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/live/basic/studio/dolist.html',
	    remoteSort	: true,
	    sortInfo	: {
            field		: 'id',
            direction	: 'DESC'
		},
		baseParams	: {
			start	: 0,
			limit	: main.pageSize
		},
		autoLoad		: true,
	    root			: 'dataset',
	 	totalProperty	: 'total',
	    fields			: ['id', 'title', 'author', 'studiono', 'userid', 'thumb', 'status', 'olstatus', 'regname',
	       'airtime', 'link', 'origin', 'iscasual', 'neartime', 'lasttime', 'seatcoin', 'ishot', 'nowforwardname',
	       'istop', 'starlv', 'isrecommend', 'viewer', 'tags', 'tagids', 'stime', 'rtmp', 'record', 'defforwardname',
	       'nowforwardids', 'defforwardids', 'isapp', 'oltools', 'isdoubt', 'warn', 'testing', 'iscurated']
	});
 	grid = {
		xtype		: 'grid',
		title		: response.title,
	    store		: store,
		region		: 'center', 
	    columns		: [
	        sm,
			{header: '编号[ID]', width:60, sortable:true, dataIndex:'id'},
			{header: '直播间标题[Title]', width:120, dataIndex:'title', renderer:function(v,meta,obj){
				return '<a href="'+obj.get('link')+'" target="_blank">'+v+'</a>';
			}},
			{header: '主播昵称[AnchorNick]', width:80, dataIndex:'author'},
			{header: '分类[Tag]', width:60, dataIndex:'tags'},
			{header: '状态[Status]', width:60, sortable:true, dataIndex:'status', renderer:function(v) {
				return response.status[v];
			}},
			{header: '是否直播[IsLive]', width:60, sortable:true, dataIndex:'olstatus', renderer:function(v){
				return response.yes2no[v];
			}},
			{header: '观众数[Viewer]', width:60, sortable:true, dataIndex:'viewer'},
			{header: '最近开播[NearTime]', width:80, sortable:true, dataIndex:'lasttime'},
			{header: '薪资等级[StarLv]', width:60, dataIndex:'starlv'},
			{header: '是否可疑 [IsSuspicion]', width:80, sortable:true, dataIndex:'isdoubt', renderer:function(v,mata,obj){
				return response.yes2no[v]+'['+obj.get('warn')+']';
			}},
			{header: '是否推荐 [IsRecommended]', width:80, sortable:true, dataIndex:'isrecommend', renderer:function(v){
				(v > 0) && (v = 1);
				return response.yes2no[v];
			}},
			{header: '是否签约[Signed]', width:60, dataIndex:'origin', sortable:true, renderer:function(v){
				return response.yes2no[v];
			}},
			{header: '是否星标推荐[IsCurated]', width:80, dataIndex:'iscurated', sortable:true, renderer:function(v){
				return response.yes2no[v];
			}},
			{header: '是否略质流[IsCasualRTMP]', width:80, dataIndex:'iscasual', sortable:true, renderer:function(v){
				return response.yes2no[v];
			}},
			{header: '是否APP开播 [IsApp]', width:80, sortable:true, dataIndex:'isapp', renderer:function(v,meta,obj){
				var oltools = obj.get('oltools');
				return ((oltools.length > 0)? oltools+'-':'')+response.yes2no[v]
			}},
			{header: '是否测试 [IsTester]', width:80, sortable:true, dataIndex:'testing', renderer:function(v){
				return response.yes2no[v];
			}},
			{header: '定位区域[Location]', width:80, dataIndex:'regname'},
			{header: '直播日志', width:80, dataIndex:'record', renderer:function(v,meta,obj){
				return '<a href="'+obj.get('record')+'" target="_blank">明细[Details]</a>';
			}},
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
		listeners	: {
			'destroy':function(){
    			win && win.close();
    			imwin && imwin.close();
    		},'rowdblclick':function(grid, index, e){
		    	var data = grid.store.getAt(index).copy();
		    	addForm(data);
		    },
		    'render':function(obj){
				main.gridRender(obj, ['thumb']);
	    	}
		},	
	    sm			: sm,
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
				store.reload(); 
			}
	    },'-',{
			text	: '设置/取消[推荐]',
			iconCls	: 'icon-right',
			url		: '/admin/live/basic/studio/dosets.html',
			handler : function() {
				doSets('isrecommend');
			}
		},'-',{
			text	: '设置/取消[Curated]',
			iconCls	: 'icon-heart',
			url 	: '/admin/live/basic/studio/dosets.html',
			handler : function() {
				doSets('iscurated');
			}
		},'-',{
			text	: '设置IM时间',
			iconCls	: 'icon-edit',
			handler : function() {
				doImTime();
			}
		},'-',{
			text	: '状态恢复',
			iconCls	: 'icon-play',
			url		: '/admin/live/basic/studio/dostatus.html',
			handler : function() {
				doStatus();
			}
		},'-',{
			text	: '重置机器人',
			iconCls	: 'icon-key',
			handler : function(){
				var rcs = grid.sm.getSelections();
				if(Ext.isEmpty(rcs)) {
					Ext.Msg.alert(GLang['30003'], GLang['30020']);
					return;
				}
				var ids= [];
				Ext.each(rcs, function(item){
					ids.push(item.get('id'));
				});
				Ext.Ajax.request({
					url		: '/admin/live/im/robotsreset.html',
					params	: {'ids':ids.join(',')},
					success : function(resp, req){
						var data = Ext.decode(resp.responseText);
						var msg  = (data.code == 0)? GLang['30027']:data.msg;
						Ext.Msg.alert(GLang['30003'], msg);
					}
				});
			}
		},'-','主播[ID]:',{
			xtype       : 'textfield',
			id	    	: sid.userid,
			width	    : 80
		},'标题/昵称:',{
			xtype       : 'textfield',
			id	    	: sid.query,
			width	    : 80
		},'状态:',{
			xtype		: 'combo',
			store		: new Ext.data.ArrayStore({
		        fields: ['id','name'],
		        data: main.cv2Array(response.status)
		    }),
			displayField	: 'name',
			valueField		: 'id',
			mode			: 'local',
			triggerAction	: 'all',
			emptyText		: 'selected...',
			width			: 80,
			id  			: sid.status
		},'标签分类',{
			xtype		: 'combo',
			store		: new Ext.data.JsonStore({
				url	: '/admin/live/share/dotags.html',
				autoDestroy: true,
				fields: ['id', 'name'],
				root: 'dataset'
			}),
			id  			: sid.tagid,
			displayField	: 'name',
			valueField		: 'id',
			emptyText		: 'selected...',
			minChars		: 1,
			 pageSize		: 10,
            listWidth		: 258,
            width	    	: 100,
			typeAhead		: true,
			typeAheadDelay  : 0,
			triggerAction	: 'all',
			enableKeyEvents : true,
			mode			: 'remote'
		},'-',{
			text			: '检索',
			iconCls			: 'icon-search',
			handler: function() {
				store.baseParams.userid   = Ext.getCmp(sid.userid).getValue();
				store.baseParams.tagid    = Ext.getCmp(sid.tagid).getValue();
				store.baseParams.status   = Ext.getCmp(sid.status).getValue();
				store.baseParams.query    = Ext.getCmp(sid.query).getValue();
				store.reload(); 
			}
		}],
		bbar		: new Ext.PagingToolbar({
			pageSize	: main.pageSize,
			store		: store,
			displayInfo	: true
		})
	};
	return grid;
}();